//
//  CZQResumeIfoViewController.m
//  coachmanage
//
//  Created by 众拳科技 on 2018/3/13.
//  Copyright © 2018年 众拳科技. All rights reserved.
//

#import "CZQResumeIfoViewController.h"
#import "CZQResumIfoTableViewCell.h"
#import "CZQJobTableViewCell.h"
#import "CZQJobInfoTableViewCell.h"
#import "CZQphotoShowTableViewCell.h"
#import "CZQCerTableViewCell.h"
#import "CZQDescripTableViewCell.h"
#import "CZQMyInfoHeadView.h"
#import "CZQResumeSetViewController.h"
#import "CZQEidtJobViewController.h"
#import "CZQLongViewController.h"
#import "CZQEidtResumeViewController.h"
#import "CZQMyDescripView.h"
#import "CZQResumeModel.h"
#import "MOFSBottomView.h"
#import "CZQAddResumeViewController.h"
@interface CZQResumeIfoViewController () <UITableViewDelegate,UITableViewDataSource,CZQphotoShowTableViewCellDelegate>
{
    
    //第一次进来
    BOOL _isFirst;
}
/**
 简历完善度
 */
@property(nonatomic,weak)UIButton *howBtn;

/**
 是否公开
 */
@property(nonatomic,weak)UILabel *publicLab;


/**
 存放擅长数据
 */
@property(nonatomic,strong)NSMutableArray *longArrM;

//自我描述
@property(nonatomic,strong)NSString *myDescrip;
/**
 //数据源
 */
@property(nonatomic,strong)NSMutableArray *dataArr;

@property(nonatomic,strong)MOFSBottomView *footView;

/**
 教练简历数据
 */
@property(nonatomic,strong)CZQResumeModel *resumeModel;

/**
 //展示图片数据
 */
@property(nonatomic,strong)NSMutableArray *photoShowdataArrM;


/**
 tableView
 */
@property(nonatomic,weak)UITableView *tableView;

@property (nonatomic , strong) ZLPhotoPickerBrowserPhoto *photo;

@end

@implementation CZQResumeIfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    
    
    if (self.isLook) {
        self.title = @"简历预览";
    }else
    {
        self.title = @"我的简历";
    }
    
    //读取信息
    self.resumeModel = [CZQResumeModel resume];
    
    self.resumeModel.UserID = [[NSUserDefaults standardUserDefaults]objectForKey:@"UserID"];
    
    
    // 添加一个通知刷新数据
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(save) name:@"resume" object:nil];
    
    
    
    [self handleData];
    
    [self loadData];
    
}
-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:YES];
    WS(weakSelf);
    
    
    
    
    
    
//    if (_isFirst) {
//
//        //更新简历数据
//        [self save];
//
//    }
//
//    _isFirst = YES;
//
//    [self.tableView reloadData];
    
}

-(void)dealloc
{
    //移除观察者 self
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

/**
 数据处理
 */
-(void)handleData
{
    
    self.dataArr = [NSMutableArray arrayWithArray:@[@"基本信息",@"求职意向",@"图片展示",@"擅长",@"工作经历",@"获得证书",@"学习培训",@"教育经历",@"自我描述"]];
    
    [self.tableView reloadData];
    
}

-(void)loadData{
    
    
    NSUserDefaults *userDetault = [NSUserDefaults standardUserDefaults];
    
    NSString *userId = [userDetault objectForKey:@"UserID"];
    
    NSString *url =[NSString stringWithFormat:@"%@/%@",Get_Resume,userId];
    
    [MBProgressHUD showMessage:@"加载中。。。" toView:self.view];
    
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    
    [params setObject:userId forKey:@"UserID"];
    [params setObject:@"1" forKey:@"page"];
    [params setObject:@"10" forKey:@"rows"];
    
    [HTTPTool GET:url parameters:params
     
          success:^(id responseObject){
              
              [MBProgressHUD hideHUDForView:self.view];
              
              NSLog(@"%@==%@",url,responseObject);
              
              if (responseObject && [[responseObject objectForKey:@"Code"] intValue] == 0) {
                  
                  NSArray *arr = [responseObject objectForKey:@"rows"] ;
                  
                  if (arr.count > 0) {
                      CZQResumeModel *resumeModel  = [CZQResumeModel mj_objectWithKeyValues:[arr firstObject]];
                      
                      self.resumeModel = resumeModel;
                      
                      
                      [self.tableView reloadData];
                  }
                  
                  
              }
              
          }
     
          failure:^(NSError *error){
              
              [self.tableView.mj_header endRefreshing];
              
              [MBProgressHUD hideHUDForView:self.view];
          }];
}


#pragma mark - 懒加载
-(NSMutableArray *)longArrM
{
    if (!_longArrM) {
        _longArrM = [NSMutableArray array];
    }
    
    return _longArrM;
}

-(NSMutableArray *)dataArr
{
    if (!_dataArr) {
        
        _dataArr = [NSMutableArray array];
        
    }
    
    return _dataArr;
}


/**
 图片展示数据

 @return arr
 */
-(NSMutableArray *)photoShowdataArrM
{
    if (!_photoShowdataArrM) {
        
        _photoShowdataArrM = [NSMutableArray array];
        
    }
    
    return _photoShowdataArrM;
}

-(UITableView *)tableView
{
    if (!_tableView) {
        
        UITableView *tableView=[[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        
        tableView.delegate=self;
        
        tableView.dataSource=self;
        
        
        tableView.estimatedRowHeight = 100;
        
        [self.view addSubview:tableView];
        
        [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.edges.mas_equalTo(self.view);
            
        }];
        
        tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        
        
        //头尾
        if (self.isLook == NO) {
            
            UIView *headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 50)];
            headView.backgroundColor = CSBlackColor;
            [self.view addSubview:headView];
            
            UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
            self.howBtn = btn;
            [btn setTitle:@"简历完善度90%"];
            [btn setImage:@""];
            [headView addSubview:btn];
            [btn mas_remakeConstraints:^(MASConstraintMaker *make) {
                
                make.top.bottom.mas_equalTo(headView);
                make.left.mas_equalTo(headView).offset(20);
                
            }];
            
            UILabel *stausLab = [UILabel new];
            self.publicLab = stausLab;
            stausLab.text = @"状态:公开";
            stausLab.font = MidFont;
            stausLab.textColor = CSWhiteColor;
            [headView addSubview:stausLab];
            [stausLab mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.top.bottom.mas_equalTo(headView);
                make.right.mas_equalTo(headView).offset(-20);
            }];
            
            tableView.tableHeaderView = headView;
            
            //尾
            MOFSBottomView *bottomView = [[MOFSBottomView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 50)];
            [bottomView.cancleBtn setTitle:@"隐藏我的简历"];
            bottomView.cancleBtn.backgroundColor = CSBlackColor;
            [bottomView.cancleBtn setTitleColor:ButtonBackGroundColor];
            [bottomView.sureBtn setTitle:@"预览我的简历"];
            self.footView = bottomView;
            
            tableView.tableFooterView = self.footView;
            
            __weak __typeof(self) weakSelf = self;
            
            self.footView.cancelBlock = ^ {
                
                weakSelf.resumeModel.IsOpen = [weakSelf.resumeModel.IsOpen intValue] == 0?@"1":@"0";
                
                NSString *str = [weakSelf.resumeModel.IsOpen intValue] == 0?@"公开我的简历":@"隐藏我的简历";
                
                [weakSelf.footView.cancleBtn setTitle:str];
                
                weakSelf.publicLab.text = weakSelf.resumeModel.IsOpen?@"状态:公开":@"状态:未公开";
                
            };
            
            self.footView.commitBlock = ^ {
                
                CZQResumeIfoViewController *look = [CZQResumeIfoViewController new];
                
                look.isLook = YES;
                
                [weakSelf.navigationController pushViewController:look animated:YES];
                
            };
            
        }
        
        //注册

        
        [tableView registerClass:[CZQMyInfoHeadView class] forHeaderFooterViewReuseIdentifier:@"head"];
        
        [tableView registerNib:[UINib nibWithNibName:@"CZQResumIfoTableViewCell" bundle:nil]  forCellReuseIdentifier:@"CZQResumIfoTableViewCell"];
        
        [tableView registerNib:[UINib nibWithNibName:@"CZQJobTableViewCell" bundle:nil]  forCellReuseIdentifier:@"CZQJobTableViewCell"];
        
        [tableView registerNib:[UINib nibWithNibName:@"CZQJobInfoTableViewCell" bundle:nil]  forCellReuseIdentifier:@"CZQJobInfoTableViewCell"];
        
        [tableView registerNib:[UINib nibWithNibName:@"CZQphotoShowTableViewCell" bundle:nil]  forCellReuseIdentifier:@"CZQphotoShowTableViewCell"];
        
        [tableView registerNib:[UINib nibWithNibName:@"CZQCerTableViewCell" bundle:nil]  forCellReuseIdentifier:@"CZQCerTableViewCell"];
        
        [tableView registerNib:[UINib nibWithNibName:@"CZQDescripTableViewCell" bundle:nil]  forCellReuseIdentifier:@"CZQDescripTableViewCell"];
        
        
        _tableView = tableView;
    }
    return _tableView;
}

#pragma mark - UITableViewDataSource

//行数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.dataArr.count;
}

//列数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 4) {
        return self.resumeModel._WorkExp.count;
    }
    if (section == 5) {
        return self.resumeModel._CertificateExp.count;
    }
    if (section == 6) {
        return self.resumeModel._TrainingExp.count;
    }
    if (section == 7) {
        return self.resumeModel._EducationExp.count;
    }
    return 1;
}

//cell内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (indexPath.section == 0) {
        //基本信息
        CZQResumIfoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CZQResumIfoTableViewCell"];
        
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        //头像
        [cell.iconImageView sd_setImageWithURL:[NSURL URLWithString:self.resumeModel.Avatar] placeholderImage:PlaceHold];
        
        //名字
        cell.nameLable.text = self.resumeModel.RealName?self.resumeModel.RealName:self.resumeModel.NickName;
        
        //性别
        cell.sexImageView.image = [self.resumeModel.Sex isEqualToString:@"0"]?[UIImage imageNamed:@"icon_man"]:[UIImage imageNamed:@"icon_women"];
        
        //描述
        cell.statuLable.text = self.resumeModel.Description;
        
        NSString *bir = self.resumeModel.BirthDay.length >1?[self.resumeModel.BirthDay substringFromIndex:self.resumeModel.BirthDay.length -2]:@"";
        
        NSArray *arr = @[isBlankString(self.resumeModel.WorkTime, @""),bir,isBlankString(self.resumeModel.Education, @""),isBlankString(self.resumeModel.Height, @""),isBlankString(self.resumeModel.Weight, @"")];
        
        for (int i = 0 ; i < arr.count; i ++) {
            UIButton *btn = (UIButton *)cell.infoArrBtn[i];
            
            [btn setTitle:arr[i]];
        }
        
        return cell;
    }
        else if (indexPath.section == 1){
        //求职意向
        CZQJobTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CZQJobTableViewCell"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        /**
         职位
         */
        cell.job1Lable.text = self.resumeModel.HopePosition;

        /**
         城市
         */
        cell.city1Lale.text = self.resumeModel.HopeCity;


        /**
         薪资
         */
        cell.money1Lable.text = self.resumeModel.HopeSalary;

        /**
         在职状态
         */
        cell.typeLable.text = self.resumeModel.HopeStatus;


        return cell;
    }
    else if (indexPath.section == 2){
        //图片展示
        CZQphotoShowTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CZQphotoShowTableViewCell"];

        cell.selectionStyle = UITableViewCellSelectionStyleNone;

        cell.delegate = self;

        cell.section = indexPath.section;



        if (self.resumeModel.Pics.length > 0) {
            cell.arrM = [NSMutableArray arrayWithArray:[self.resumeModel.Pics componentsSeparatedByString:@","]];
        }else
        {
            cell.arrM = nil;
        }

        cell.model = self.resumeModel;

        [cell.addBtn setImage:@"icon_add"];

        [cell.addBtn setTitle:@""];

        return cell;
    }
    else if (indexPath.section == 3){
        //擅长
        CZQphotoShowTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CZQphotoShowTableViewCell"];

        cell.selectionStyle = UITableViewCellSelectionStyleNone;

         cell.delegate = self;

        cell.section = indexPath.section;

        [cell.addBtn setImage:@"icon_add"];

        [cell.addBtn setTitle:@"添加擅长技能"];

        if (self.resumeModel.FavTags.length > 0) {
            self.longArrM = [NSMutableArray arrayWithArray:[self.resumeModel.FavTags componentsSeparatedByString:@","]];
        }else
        {
            cell.arrM = nil;
        }


        cell.arrM = self.longArrM;

        cell.model = self.resumeModel;


        return cell;
    }
    else if (indexPath.section == 4){
        //工作经历
        CZQJobInfoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CZQJobInfoTableViewCell"];

        cell.selectionStyle = UITableViewCellSelectionStyleNone;

        CZQWorkExpModel *workModel =[CZQWorkExpModel mj_objectWithKeyValues:self.resumeModel._WorkExp[indexPath.row]];

        cell.timeLable.text = [NSString stringWithFormat:@"%@至%@",workModel.BeginDate,workModel.EndDate];

        cell.addressLable.text = workModel.CompanyName;

        cell.jobLable.text = [NSString stringWithFormat:@"岗位：%@",workModel.Position];

        cell.infoLable.text = workModel.Intro;

        return cell;
    }
    else if (indexPath.section == 5){
        //获得证书
        CZQCerTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CZQCerTableViewCell"];

        cell.selectionStyle = UITableViewCellSelectionStyleNone;

        CZQCertificateExpModel *cerModel =[CZQCertificateExpModel mj_objectWithKeyValues:self.resumeModel._CertificateExp[indexPath.row]];

        [cell.cerImageView sd_setImageWithURL:[NSURL URLWithString:cerModel.Pic] placeholderImage:[UIImage imageNamed:@"icon_certificate"]];

        cell.cerNameLable.text = cerModel.Name;

        cell.cerAdreessLable.text = cerModel.Org;

        cell.cerTimeLable.text = cerModel.BeginDate;

        return cell;
    }
    else if (indexPath.section == 6){

        //学习培训
        CZQCerTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CZQCerTableViewCell"];

        cell.selectionStyle = UITableViewCellSelectionStyleNone;

        CZQTrainingExpModel *ctrainModel =[CZQTrainingExpModel mj_objectWithKeyValues:self.resumeModel._TrainingExp[indexPath.row]];

        [cell.cerImageView sd_setImageWithURL:[NSURL URLWithString:ctrainModel.Logo] placeholderImage:PlaceHold];

        cell.cerNameLable.text = ctrainModel.Content;

        cell.cerAdreessLable.text = ctrainModel.Org;

        cell.cerTimeLable.text = ctrainModel.BeginDate;

        return cell;
    }
    else if (indexPath.section == 7){
        //教育经历
        CZQJobInfoTableViewCell *studyCell = [tableView dequeueReusableCellWithIdentifier:@"CZQJobInfoTableViewCell"];

        studyCell.selectionStyle = UITableViewCellSelectionStyleNone;

        CZQEducationExpModel *educationModel = [CZQEducationExpModel mj_objectWithKeyValues:self.resumeModel._EducationExp[indexPath.row]];

        studyCell.timeLable.text = [NSString stringWithFormat:@"%@至%@",educationModel.BeginDate,educationModel.EndDate];

        studyCell.addressLable.text = educationModel.School;

        studyCell.jobLable.text = educationModel.Profession;

        studyCell.infoLable.text = educationModel.Degree;

        return studyCell;
    }else if (indexPath.section == 8){


        //自我评价
        CZQDescripTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CZQDescripTableViewCell"];

        cell.selectionStyle = UITableViewCellSelectionStyleNone;

        if (self.resumeModel.Sign) {
            cell.myDescripLable.text = self.resumeModel.Sign;
            cell.myDescripLable.textColor = [UIColor blackColor];
        }else
        {
            cell.myDescripLable.text = @"介绍下自己";

            cell.myDescripLable.textColor = [UIColor darkGrayColor];

        }


        return cell;


    }
    
    return nil;
    
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 60;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.00001;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    return [[UIView alloc]initWithFrame:CGRectZero];
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{

    WS(weakSelf);

    CZQMyInfoHeadView *head = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"head"];

    head.titileLable.text = [self.dataArr objectAtIndex:section];

    if (self.isLook == YES) {
        head.eidtBtn.hidden = YES;
    }

    [head.eidtBtn bk_removeEventHandlersForControlEvents:UIControlEventTouchUpInside];

    //编辑简历
    [head.eidtBtn bk_addEventHandler:^(id sender) {

        if (section == 0) {

            //基本信息
            CZQResumeSetViewController *resureSetVC = [CZQResumeSetViewController new];

            resureSetVC.resumeModel = weakSelf.resumeModel;

            resureSetVC.saveResume = ^{


                [weakSelf save];
            };

            [weakSelf.navigationController pushViewController:resureSetVC animated:YES];

        }else if (section == 1)
        {
            //求职意向
            CZQEidtJobViewController *eidtJobVC = [CZQEidtJobViewController new];

            eidtJobVC.resumeModel = weakSelf.resumeModel;

            eidtJobVC.saveResume = ^{

                [weakSelf save];

            };

            [weakSelf.navigationController pushViewController:eidtJobVC animated:YES];

        }
        else if (section == 2)
        {
            //图片展示

            [weakSelf logoSelect:nil];



        }
        else if (section == 3)
        {
            //擅长
            CZQLongViewController *longVC = [CZQLongViewController new];
            longVC.resumeModel = weakSelf.resumeModel;
//            longVC.seletDataArrM = self.longArrM;
            
            longVC.saveBlock = ^{
                
                [weakSelf save];
                
            };

            [weakSelf.navigationController pushViewController:longVC animated:YES];

        }else if (section == 8)
        {
            //自我描述
            CZQMyDescripView *sourceAlertView = [[CZQMyDescripView alloc] init];


            sourceAlertView.textView.max = 30;

            sourceAlertView.textView.min = 0;

            [sourceAlertView.textView becomeFirstResponder];

            sourceAlertView.textView.placeLable.text = @"请介绍下自己吧";

            sourceAlertView.textView.toolPlaceLable.text = [NSString stringWithFormat:@"%ld/%ld",sourceAlertView.textView.min,sourceAlertView.textView.max];

            sourceAlertView.commitBlock = ^(NSString *str) {


                weakSelf.resumeModel.Sign = str;

                [weakSelf save];


            };

            [sourceAlertView showWithAnimation];

        }else
        {

            CZQEidtResumeViewController*eidt = [CZQEidtResumeViewController new];

            eidt.section = section;

            eidt.resumeModel = weakSelf.resumeModel;

            [weakSelf.navigationController pushViewController:eidt animated:YES];

            if (section == 4)
            {
                //工作经历

                eidt.title = @"工作经历";


            }
            else if (section == 5)
            {
                //获得证书

                eidt.title = @"获得证书";


            }
            else if (section == 6)
            {
                //学习培训

                eidt.title = @"学习培训";


            }
            else if (section == 7)
            {
                //教育经历

                eidt.title = @"教育经历";


            }

        }




    } forControlEvents:UIControlEventTouchUpInside];

    return head;
}



-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //当离开某行时，让某行的选中状态消失
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if (self.isLook) {
        return;
    }
    
    NSDictionary *dic;
    
    NSString *title ;
    
    if (indexPath.section == 4){
        //工作经历
        title = @"工作经历";
        //        CZQWorkExpModel *workModel =[CZQWorkExpModel mj_objectWithKeyValues:self.resumeModel.WorkExp[indexPath.row]];
        
        dic = self.resumeModel._WorkExp[indexPath.row];
        
    }
    else if (indexPath.section == 5){
        //获得证书
        title = @"获得证书";
        //        CZQCertificateExpModel *cerModel =[CZQCertificateExpModel mj_objectWithKeyValues:self.resumeModel.CertificateExp[indexPath.row]];
        dic = self.resumeModel._CertificateExp[indexPath.row];
        
    }
    else if (indexPath.section == 6){
        
        //学习培训
        title = @"学习培训";
        //        CZQTrainingExpModel *ctrainModel =[CZQTrainingExpModel mj_objectWithKeyValues:self.resumeModel.TrainingExp[indexPath.row]];
        dic = self.resumeModel._TrainingExp[indexPath.row];
        
        
    }
    else if (indexPath.section == 7){
        //教育经历
        title = @"教育经历";
        //        CZQEducationExpModel *educationModel = [CZQEducationExpModel mj_objectWithKeyValues:self.resumeModel.EducationExp[indexPath.row]];
        dic = self.resumeModel._EducationExp[indexPath.row];
        
    }else
    {
        return;
    }
    
    CZQAddResumeViewController *add = [CZQAddResumeViewController new];
    
    add.section = indexPath.section;
    
    add.resumeModel = self.resumeModel;
    
    add.dic = dic;
    
    add.row = indexPath.row;
    
    
    
    
    add.title = [NSString stringWithFormat:@"编辑%@",title];
    
    [self.navigationController pushViewController:add animated:YES];
    
}

#pragma Logo图片选择
-(void)logoSelect:(UIButton *)photoSelect{
    
    ZLPhotoPickerViewController *pickerVc = [[ZLPhotoPickerViewController alloc] init];
    
    if (photoSelect.tag == 0) {
        
    }
    
    pickerVc.maxCount = 9;
    
    // Jump AssetsVc
//    pickerVc.status = PickerViewShowStatusSavePhotos;
    // Recoder Select Assets
    //    pickerVc.selectPickers = self.assets;
    // Filter: PickerPhotoStatusAllVideoAndPhotos, PickerPhotoStatusVideos, PickerPhotoStatusPhotos.
    
    pickerVc.photoStatus = PickerPhotoStatusPhotos;
    // Desc Show Photos, And Suppor Camera
    pickerVc.isShowCamera = YES;
    pickerVc.topShowPhotoPicker = YES;
    
    // CallBack
    __weak typeof(self)weakSelf = self;
    
    pickerVc.callBack = ^(NSArray<ZLPhotoAssets *> *status){
        
        for (ZLPhotoAssets *assets in status) {
            
            ZLPhotoPickerBrowserPhoto *photo = [ZLPhotoPickerBrowserPhoto photoAnyImageObjWith:assets];
            
            photo.asset = assets;
            
            
            UIImage *image = nil;
            
            //拍照
            if ([photo.asset isKindOfClass:[UIImage class]]) {
                
                image = (UIImage *)photo.asset;
            }
            else{
                image = [assets thumbImage];
                
            }
            
            
            
            [weakSelf uploadImage:image];
        }
        
        
        
        
            //            break;
        
        
    };
    
    [pickerVc showPickerVc:self];
}

#pragma mark - 刷新

-(void)CZQphotoShowTableViewCellRefreashData
{
    
    [self save];
    
}

#pragma mark - 更新简历数据

-(void)save
{
    
    WS(weakSelf);
    
    if (self.photoShowdataArrM.count > 0) {
        self.photoShowdataArrM = [NSMutableArray arrayWithArray:[self.resumeModel.Pics componentsSeparatedByString:@","]];
    }
    
    self.publicLab.text = self.resumeModel.IsOpen?@"状态:公开":@"状态:未公开";
    
    weakSelf.resumeModel.IsOpen = [weakSelf.resumeModel.IsOpen intValue] == 0?@"1":@"0";
    
    NSString *str = [weakSelf.resumeModel.IsOpen intValue] == 0?@"公开我的简历":@"隐藏我的简历";
    
    [weakSelf.footView.cancleBtn setTitle:str];
    
    [MBProgressHUD showMessage:@"请求中..." toView:self.view];
    
    
    NSDictionary *params = [self.resumeModel toDictionary];
    
    NSLog(@"%@",params);
    
    
    
    [HTTPTool POSTRaw:Post_Resume_Operate parameters:params
     
              success:^(id responseObject){
                  
                  [MBProgressHUD hideHUDForView:self.view];
                  
                  if (responseObject && [[responseObject objectForKey:@"Code"] intValue] == 0) {
                      
                      [MBProgressHUD showText:@"保存成功"];
                      
                      self.resumeModel.ID = [responseObject objectForKey:@"ResumeID"];
                      
                      //归档教练数据
                      [CZQResumeModel saveResume:self.resumeModel];
                      
                      [self.tableView reloadData];
                  }
                  
              }
     
              failure:^(NSError *error){
                  
                  [MBProgressHUD hideHUDForView:self.view];
              }];
    
}

    
#pragma mark 上传头像
-(void)uploadImage:(UIImage *)image{
    
    
    
    NSData *imageData;
    
    
    WS(weakSelf);
    
    imageData  = UIImageJPEGRepresentation(image,0.1);
    
    [MBProgressHUD showMessage:@"上传中.." toView:self.view];
    
    RAYUploader *upload = [RAYUploader defaultUploader];
    
    [upload uploadWithData:imageData complete:^(QNResponseInfo *info, NSString *key, NSDictionary *resp) {
        
        [MBProgressHUD hideHUDForView:self.view];
        
        if (key) {
            
            dispatch_async(dispatch_get_main_queue(), ^{
                
                NSString *picUrl = [NSString stringWithFormat:@"%@%@",QiNiuBase,key];
                
                [weakSelf.photoShowdataArrM addObject:  picUrl];
                
                weakSelf.resumeModel.Pics = [weakSelf.photoShowdataArrM componentsJoinedByString:@","];
                
                [weakSelf save];
                
                
            });
            
        }
        
    }];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
